package mi.payment.transaction;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import lainey.ui.widget.TitleView;
import mi.payment.R;
import mi.payment.utils.MoneyUtils;

public abstract class V2SwingCardActivity extends V2BaseSwingCardActivity {

    private TextView mTvAmount;
    private TextView mTvCardHint;

    private View mOnlyIcView;
    private View mOnlyNfcView;
    private View mIcAndNfcView;
    private View mNfcView;
    private View mMagView;

    public TextView mTvTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.consume_activity_swing_card);
        initView();
    }

    private void initView() {
        TitleView titleView = findViewById(R.id.title_view);
        mTvTitle = titleView.getCenterTextView();
        titleView.setLeftImageOnClickListener(
                v -> onBackPressed()
        );

        mTvAmount = findViewById(R.id.tv_value);
        mTvCardHint = findViewById(R.id.tv_hint);

        mOnlyIcView = findViewById(R.id.iv_only_chip_card);
        mOnlyNfcView = findViewById(R.id.view_only_nfc_card);
        mIcAndNfcView = findViewById(R.id.iv_nfc_chip_card);
        mNfcView = findViewById(R.id.iv_nfc_card);
        mMagView = findViewById(R.id.iv_mag_card);

        showDefaultView();
    }

    @Override
    public void setAmount(long amount) {
        super.setAmount(amount);
        String text = getString(R.string.money_only_symbol) + MoneyUtils.longCent2DoubleMoneyStr(amount);
        mTvAmount.setText(text);
    }

    public void showAmountView(boolean isShow) {
        if (isShow) {
            mTvAmount.setVisibility(View.VISIBLE);
        } else {
            mTvAmount.setVisibility(View.GONE);
        }
    }

    public void showForceNfcView(boolean isForceNFC) {
        if (isForceNFC) {
            mTvCardHint.setText(R.string.swing_card_no_ic);
            mOnlyIcView.setVisibility(View.GONE);
            mOnlyNfcView.setVisibility(View.GONE);
            mIcAndNfcView.setVisibility(View.GONE);
            mNfcView.setVisibility(View.VISIBLE);
            mMagView.setVisibility(View.VISIBLE);
        } else {
            showDefaultView();
        }
    }

    public void showOnlyNfcView(boolean isNfc) {
        if (isNfc) {
            mTvCardHint.setText(R.string.swing_card_mag);
            mOnlyIcView.setVisibility(View.GONE);
            mOnlyNfcView.setVisibility(View.VISIBLE);
            mIcAndNfcView.setVisibility(View.GONE);
            mNfcView.setVisibility(View.GONE);
            mMagView.setVisibility(View.GONE);
        } else {
            showDefaultView();
        }
    }

    public void showOnlyIcView(boolean isIc) {
        if (isIc) {
            mTvCardHint.setText(R.string.swing_card_ic);
            mOnlyIcView.setVisibility(View.VISIBLE);
            mOnlyNfcView.setVisibility(View.GONE);
            mIcAndNfcView.setVisibility(View.GONE);
            mNfcView.setVisibility(View.GONE);
            mMagView.setVisibility(View.GONE);
        } else {
            showDefaultView();
        }
    }

    private void showDefaultView() {
        mTvCardHint.setText(R.string.swing_card_hint);
        mOnlyIcView.setVisibility(View.GONE);
        mOnlyNfcView.setVisibility(View.GONE);
        mIcAndNfcView.setVisibility(View.VISIBLE);
        mNfcView.setVisibility(View.GONE);
        mMagView.setVisibility(View.VISIBLE);
    }


}
